﻿using System;
using System.Windows;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Notes.Model;
using Notes.Helpers;
using System.Windows.Media;
using Microsoft.Phone.Shell;

namespace Notes
{
    public partial class PicturePage : PhoneApplicationPage
    {
        private string selectedIndex;

        public PicturePage()
        {
            InitializeComponent();

            #region ApplicationBar
            // set applicatiobar button names
            ApplicationBar.BackgroundColor = (Color)Resources["PhoneBackgroundColor"];
            ApplicationBarIconButton btnDel = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
            btnDel.Text = AppResources.strBarDel;
            #endregion
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
            {
                int index = int.Parse(selectedIndex);
                DataContext = App.EditViewModel.Photos[index];
            }
            else
            {
                Messenger.ShowMessage(AppResources.strMessageTitleError,AppResources.strMessageTextPhotoNotFound);
                NavigationService.Navigate(new Uri("/MainPage.xaml",UriKind.Relative));
            }
        }

        private void ApplicationBarDelete_Click(object sender, EventArgs e)
        {
            int index = int.Parse(selectedIndex);
            App.EditViewModel.DeletePhoto(App.EditViewModel.Photos[index]);
            NavigationService.GoBack();
        }
    }
}